package com.jsu.user.controller.v1;

import com.jsu.user.service.impl.WebUserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.model.common.dtos.ResponseResult;
import org.example.model.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;

@Slf4j
@RestController
@RequestMapping("/user/web/v1/user")
@Api(tags = "用户信息控制器")
public class WebUserController {
    @Autowired
    private WebUserServiceImpl webUserService;

    @ApiOperation(value = "更新用户信息")
    @PostMapping("/update")
    public ResponseResult updateUser(@RequestBody User user){
        log.info("updateUser user:{}", user);
        return webUserService.updateUser(user);
    }

    @ApiOperation(value = "获取当前用户信息")
    @GetMapping("/get")
    public ResponseResult getUser(@RequestHeader("token") String token){
        return webUserService.findUser(token);
    }

    @ApiOperation(value = "根据用户id获取用户信息")
    @GetMapping("/get/{phone}")
    public ResponseResult getUserByPhone(@PathVariable("phone") int phone){
       return webUserService.findUserByPhone(phone);
    }

    @ApiOperation(value = "根据phone获取用户信息")
    @GetMapping("/get/user/{userId}")
    public ResponseResult getUserById(@PathVariable("userId") int userId){
        return webUserService.findUserById(userId);
    }

    @ApiOperation(value = "获取所有用户信息")
    @GetMapping("/get/all")
    public ResponseResult getAllUser(){
        return webUserService.findAllUser();
    }

    @ApiOperation(value = "添加用户信息")
    @PostMapping("/add")
    public ResponseResult addUser(@RequestBody User user) {
        return webUserService.addUser(user);
    }

    @ApiOperation(value = "删除用户信息")
    @DeleteMapping("/delete/{userId}")
    public ResponseResult deleteUser(@PathVariable("userId") int userId) {
        return webUserService.deleteUser(userId);
    }


//    @ApiOperation(value = "获取用户的议程信息")
//    @GetMapping("/get/agenda")
//    public ResponseResult getUserAgenda(){
//        return webUserService.getUserAgenda();
//    }
//
//    @ApiOperation(value = "获取用户订阅的活动信息")
//    @GetMapping("/get/activity")
//    public ResponseResult getUserActivity(){
//        return webUserService.getUserActivity();
//    }

    @ApiOperation(value = "登出")
    @PostMapping("/logout")
    public ResponseResult loginOut(){
        return webUserService.loginOut();
    }

    @ApiOperation(value = "对用户进行模糊查询")
    @GetMapping("/search/{keyword}")
    public ResponseResult searchUser(@PathVariable("keyword") String keyword){
        return webUserService.searchUser(keyword);
    }

    @ApiOperation(value = "批量删除用户")
    @DeleteMapping("/delete/batch/{userIds}")
    public ResponseResult deleteUserBatch(@PathVariable int[] userIds) {
        log.info("deleteUserBatch userIds:{}", userIds[0]);
        return webUserService.deleteUserBatch(userIds);
    }


}
